namespace SimpleWebServices.Web
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class MaintenanceFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Maintenance>()
                .DerivesFrom<Resource>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("resource")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            string xml =
                "<resource>" +
                "<message><![CDATA[The display message.]]></message>" +
                "</resource>";

            Maintenance actual = xml.Deserialize<Maintenance>();

            Assert.Equal<string>("The display message.", actual.Message);
        }

        [Fact]
        public void deserializeEmpty()
        {
            Maintenance actual = "<resource />".Deserialize<Maintenance>();

            Assert.Null(actual.Message);
        }

        [Fact]
        public void serialize()
        {
            Maintenance obj = new Maintenance
            {
                Message = "The display message."
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/resource/message[text()='The display message.'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Maintenance());
        }

        [Fact]
        public void prop_Message()
        {
            Assert.True(new PropertyExpectations(typeof(Maintenance).GetProperty("Message"))
                .XmlElement("message")
                .IsAutoProperty<string>()
                .Result);
        }
    }
}